//
// Description: 5201. 给植物浇水
// Created by Loading on 2021/11/21.
//

#include <bits/stdc++.h>

using namespace std;

int wateringPlants(vector<int> &plants, int capacity) {
    int water = capacity;
    int n = plants.size();
    int count = 0;

    for (int i = 0; i < n; ++i) {
        if (water < plants[i]) {
            // 灌满水壶
            count += i * 2;
            water = capacity;
        }
        water -= plants[i];
        count++;
    }

    return count;
}

int main() {
    vector<int> plants = {1, 1, 1, 4, 2, 3};
    int capacity = 4;
    int res = wateringPlants(plants, capacity);
    cout << res << endl;

    return 0;
}